package menu

import (
	"context"
	"github.com/wailsapp/wails/v2/pkg/menu"
	"github.com/wailsapp/wails/v2/pkg/menu/keys"
	"github.com/wailsapp/wails/v2/pkg/runtime"
)

// 创建系统化实例化对象
type App struct {
	ctx context.Context
}

// 返回系统实例化对象
func NewApp() *App {
	return &App{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) Startup(ctx context.Context) {
	a.ctx = ctx
}

// 实现menu对象 返回menu对象
func (a *App) Menu() *menu.Menu {
	return menu.NewMenuFromItems(
		//设置第一个menu
		menu.SubMenu("supplier", menu.NewMenuFromItems(
			menu.Text("关于supplier", keys.CmdOrCtrl("z"), func(data *menu.CallbackData) {
				runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
					Type:          runtime.InfoDialog,
					Title:         "supplier",
					Message:       "基于hyperledger fabric购物商场的供应商端",
					CancelButton:  "取消",
					DefaultButton: "默认",
					Buttons:       []string{"确认"},
				})
			}),
			menu.Separator(),
			menu.Text("刷新", keys.CmdOrCtrl("o"), func(data *menu.CallbackData) {
				runtime.WindowReload(a.ctx)
			}),
			menu.Separator(),
			menu.Text("退出", keys.CmdOrCtrl("q"), func(data *menu.CallbackData) {
				runtime.Quit(a.ctx)
			}),
		),
		),
		menu.SubMenu("Test", menu.NewMenuFromItems(
			menu.Text("About", keys.CmdOrCtrl("z"), func(data *menu.CallbackData) {
				runtime.WindowReload(a.ctx)
			}),
			menu.Text("Renovate", keys.CmdOrCtrl("o"), func(data *menu.CallbackData) {
				runtime.WindowReload(a.ctx)
			}),
			menu.Separator(),
		),
		),
	)
}
